<?php

/**
 * Albireo Kernel
 *
 * @copyright  Copyright (c) 2010 Albireo Solutions
 * @package    Kernel
 */
namespace KernelModule\LogsModule\PhpModule;

use KernelModule\BasePresenter;

use Nette\Environment;
use Nette\Debug;

use KernelModule\LogsModule\LogsBluescreenFileException;

/**
 * Kernel PHP error logs detail presenter, it displays 1 log details with
 * the red page.
 *
 * @author     Pavel
 * @package    Kernel
 */
class DetailPresenter extends BasePresenter {

    /**
     * Render the log detail page which includes the red page.
     *
     * @param $hash is the hashcode identifier of the file
     */
    public function actionDefault($hash) {
        $result = $this->getLogPathOrEmpty($hash);
        if (empty($result)) {
            $this->redirect('Display:');
        }
    }

    public function renderDefault($hash) {
        $this->showMenu();
        $this->template->hash = $hash;
        $this->template->title = _("PHP Error Debug");
    }

    /**
     * Render the content of iframe, showing already generated page stored
     * in the log directory.
     *
     * @param $hash is the hashcode identifier of the file
     */
    public function actionDebuggerRed($hash) {
        $this->template->logPath = $this->getLogPathOrEmpty($hash);
    }

    public function renderDebuggerRed() {
        //all in the action
    }

    private function getLogPathOrEmpty($hash) {
        $detailModel = new Detail();
        try {
            $result = $detailModel->getDebugFile($hash); //get DEBUG filename
        } catch (LogsBluescreenFileException $e) {
            $result = "";
        }
        return $result;
    }

}